<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            width: 300px;
            height: 100px;
            border: 1px dashed blue;
            line-height: 100px; 
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>
<script>
     let obox = document.querySelector(".box");
    // 编号的内容
    let codeText = "1234567890";// 索引的范围是0-9
    let codeLength = 4;
    function getCode(codeText,codeLength) {
        let res = "";
        for (let i = 0; i < codeLength; i++) {
            let index = Math.round(Math.random() * (codeText.length-1));
            res += codeText[index];
        }
        return res;
    }
    obox.innerHTML=  getCode(codeText,codeLength);
   var time= setInterval(()=>{
      obox.innerHTML=  getCode(codeText,codeLength);
    },1000);
   var time2=setTimeout(()=>{
        clearInterval(time);
        clearTimeout(time2);
        time=null;
        time2=null;
    },10000)
    
</script>